home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 25.9 KB | 970 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 10/17/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPScrollArea
-
- SUPERCLASS: CPPVisualObject
-
- This C++ class manages a scrollable area
-
- ********************************************************************/
-
-
- #include <CPPWindow.h>
- #include <CPPScrollArea.h>
- #include <Commands.h>
- #include <mathTools.h>
-
- /*-----------------------------------------------------------------*/
- /*---------------------- CALLBACK VARIABLES -----------------------*/
- /*-----------------------------------------------------------------*/
-
- // Initialize the class member variables used in the callbacks
- CPPScrollArea *CPPScrollArea::gCurrentArea = NULL;
- ControlHandle CPPScrollArea::gVScroll = NULL;
- ControlHandle CPPScrollArea::gHScroll = NULL;
-
- /*-----------------------------------------------------------------*/
- /*-------------------------- GLOBALS ------------------------------*/
- /*-----------------------------------------------------------------*/
-
- extern Rect kEmptyRect;
- extern RGBColor RGBBlack;
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
-
- CPPScrollArea::CPPScrollArea (CPPWindow *OurWindow,
- Rect *ViewArea,
- Rect *DestArea,
- Boolean UseHScroll,
- Boolean UseVScroll,
- short hStep, short vStep) :
- CPPVisualObject (OurWindow, ViewArea, TRUE, FALSE)
- {
- MakeCPPScrollArea (OurWindow, ViewArea, DestArea,
- UseHScroll, UseVScroll, hStep, vStep);
-
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPScrollArea::CPPScrollArea (CPPWindow *OurWindow,
- Boolean UseHScroll,
- Boolean UseVScroll,
- short hStep, short vStep) :
- CPPVisualObject (OurWindow,
- &((OurWindow->GetWindow())->portRect),
- TRUE, FALSE)
- {
- Rect ViewRect;
- Rect DestRect;
-
- if (OurWindow)
- {
- ViewRect = (OurWindow->GetWindow())->portRect;
- ViewRect.left--; ViewRect.top--;
- SetRect (&DestRect, 0, 0, kPageWidth, kPageHeight);
- MakeCPPScrollArea (OurWindow, &ViewRect, &DestRect,
- UseHScroll, UseVScroll, hStep, vStep);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPScrollArea::~CPPScrollArea (void)
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPScrollArea::ClassName (void)
- {
- return "CPPScrollArea";
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPScrollArea::DoCommand (short commandID)
- /* do a command associated with a menu */
- {
- switch (commandID) {
- case kCmdCut :
- DoCut();
- break;
- case kCmdCopy :
- DoCopy();
- break;
- case kCmdPaste :
- DoPaste();
- break;
- case kCmdSelectAll :
- DoSelectAll();
- break;
- case kCmdClear :
- DoClear();
- break;
- default:
- return FALSE;
- break;
- }
-
- return TRUE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoCut (void)
- /* cut the currently selected contents */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoCopy (void)
- /* copy the currently selected contents */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoPaste (void)
- /* paste new data into the area */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoClear (void)
- /* clear the currently selected contents */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoSelectAll (void)
- /* select the entire scroll area */
- {
- RemoveSelection();
-
- MakeSelection (&this->destRect);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::RemoveSelection(void)
- /* forget about the current selection */
- {
- if (this->hasSelection)
- {
- HiliteSelection(FALSE);
- this->selRect = kEmptyRect;
- this->hasSelection = FALSE;
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::MakeSelection (Rect *newSelection)
- /* create a new selection area; deselect any which previously */
- /* existed */
- {
- if (this->hasSelection)
- RemoveSelection();
- this->selRect = *newSelection;
- this->hasSelection = TRUE;
- HiliteSelection(TRUE);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::HiliteSelection (Boolean doHilight)
- /* SUBCLASS SHOULD OVERRIDE */
- /* Turn the hilighting of the selection on or off depending on */
- /* the value of doHilight */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::IdleSelection (void)
- /* Perform whatever periodic updating is needed to hilight */
- /* the selection */
- /* SUBCLASS SHOULD OVERRIDE */
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Activate (Boolean nowActive)
- /* activate or deactivate the controls in the scroll area */
- {
- short HiliteValue = (nowActive) ? 0 : 255;
-
- CPPVisualObject::Activate(nowActive);
-
- AdjustScrollBar();
-
- if (this->VScroll)
- HiliteControl (this->VScroll, HiliteValue);
- if (this->HScroll)
- HiliteControl (this->HScroll, HiliteValue);
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPScrollArea::DoClick (EventRecord *theEvent)
- /* handle a click in the scroll area */
- {
- WindowPtr theWindow;
- short code, part;
- ControlHandle hitControl;
- Point myPt = theEvent->where;
- Boolean shiftDown = (theEvent->modifiers & shiftKey) ? TRUE : FALSE;
-
- if (!IsVisible()) return FALSE;
-
- code = FindWindow(theEvent->where, &theWindow);
- if (theWindow == this->owningWindow)
- {
- Global2Local (&myPt);
- part = FindControl(myPt, theWindow, &hitControl);
-
- // now respond to the click
- if (hitControl) // if they clicked in a scrollbar
- {
- if (hitControl == this->HScroll)
- DoHScroller (myPt, part);
- else
- if (hitControl == this->VScroll)
- DoVScroller (myPt, part);
- else
- return FALSE;
- }
- else // if they clicked in the TE area
- {
- if (PtInRect (myPt, &this->areaRect))
- {
- gVScroll = this->VScroll;
- gHScroll = this->HScroll;
- gCurrentArea = this;
- Local2Area (&myPt);
- return DoScrollAreaClick(myPt, theEvent->modifiers);
- }
- else
- return FALSE;
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPScrollArea::DoScrollAreaClick (Point clickPt, short modifiers)
- /* handle a click in the scroll area; clickPt is in area coordinates */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- // default behavior; scroll the area automatically as long
- // as the mouse is down
- while (StillDown())
- AutoScroll();
-
- return TRUE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoIdle (void)
- {
- if (this->hasSelection)
- IdleSelection ();
- }
-
- /*-----------------------------------------------------------------*/
-
- Rect *CPPScrollArea::GetAreaRect (void)
- {
- return &this->areaRect;
- }
-
- /*-----------------------------------------------------------------*/
-
- Rect *CPPScrollArea::GetBounds (void)
- /* return a rectangle in window coordinates which encloses */
- /* the whole visible scroll area and its controls*/
- {
- this->bounds = kEmptyRect;
-
- if (this->isVisible)
- {
- this->bounds = this->areaRect;
- if (this->HScroll)
- UnionRect (&((**this->HScroll).contrlRect), &this->bounds, &this->bounds);
- if (this->VScroll)
- UnionRect (&((**this->VScroll).contrlRect), &this->bounds, &this->bounds);
- }
-
- return &this->bounds;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DrawContents (void)
- /* Draw the data in the window */
- /* SUBCLASS MUST OVERRIDE */
- {
- RGBColor VColor = {65535, 65535, 65535};
- RGBColor HColor = {65535, 65535, 65535};
- long x, y;
-
- for (x = this->destRect.left; x <= this->destRect.right; x+= this->hStep)
- {
- HColor.red = HColor.green = HColor.blue = HColor.blue - 65535 / AreaWidth();
- RGBForeColor (&HColor);
- MoveTo (x, this->viewRect.top);
- LineTo (x, this->viewRect.bottom);
- }
-
- for (y = this->destRect.top; y <= this->destRect.bottom; y += this->vStep)
- {
- VColor.red = VColor.green = VColor.blue = VColor.blue -= 65535 / AreaHeight();
- RGBForeColor (&VColor);
- MoveTo (this->viewRect.left, y);
- LineTo (this->viewRect.right, y);
- }
-
- RGBForeColor (&RGBBlack);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Draw (void)
- /* set the origin and clipping rect and call the user routine */
- /* to draw the contents of the scroll area */
- {
- RgnHandle oldClip = NewRgn(),
- newClip = NewRgn();
- Rect tempRect = *GetBounds();
-
- // draw the frame and the scrollbars
- if (this->VScroll)
- Draw1Control (this->VScroll);
- if (this->HScroll)
- Draw1Control (this->HScroll);
- FrameRect (&tempRect);
-
- // set the origin so the contents can drawn naturally
- SetOrigin(this->viewRect.left-this->areaRect.left,
- this->viewRect.top-this->areaRect.top);
-
- // clip drawing to the visible area
- GetClip (oldClip);
- tempRect = this->viewRect;
- InsetRect (&tempRect, 1, 1);
- if (this->HScroll)
- tempRect.bottom++;
- if (this->VScroll)
- tempRect.right++;
- RectRgn (newClip, &tempRect);
- SectRgn (newClip, oldClip, newClip);
- SetClip (newClip);
-
- // call the user routines to draw the contents and selection
- DrawContents();
- if (this->hasSelection)
- HiliteSelection(TRUE);
-
- // restore the clip region and coordinate systems
-
- SetClip (oldClip);
- DisposeRgn(oldClip);
- DisposeRgn(newClip);
- SetOrigin(0, 0);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::MakeVisible (Boolean nowVisible)
- {
- Rect boundsRect = *GetBounds();
-
- InsetRect (&boundsRect, -1, -1);
- // exit if it is already in the desired state
- if (nowVisible == IsVisible())
- return;
-
- CPPVisualObject::MakeVisible (nowVisible);
-
- // if it is currently invisible, erase it;
- // in either case, invalidate the area to force a redraw
- if (!IsVisible())
- {
- EraseRect (&boundsRect);
- if (this->VScroll)
- HideControl(VScroll);
- if (this->HScroll)
- HideControl(HScroll);
- }
- else
- {
- if (this->VScroll)
- ShowControl(VScroll);
- if (this->HScroll)
- ShowControl(HScroll);
- this->Draw();
- }
-
- InvalRect(&boundsRect);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::TargetHilite (Boolean makeTarget)
- /* do any hiliting necessary to indicate that the scroll area is */
- /* now the target */
- /* SUBCLASS MAY OVERRIDE */
- {
- this->Activate(makeTarget);
-
- CPPVisualObject::TargetHilite(makeTarget);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::SetHorizontalStep (short stepSize)
- /* change the step size of the horizontal scroll bar; adjust */
- /* the current value of the scrollbar as necessary */
- {
- short oldValue, oldMax, newMax;
-
- if (this->hStep != stepSize)
- {
- this->hStep = stepSize;
- if (this->HScroll)
- {
- oldValue = GetCtlValue(this->HScroll);
- oldMax = GetCtlMax(this->HScroll);
-
- SetCtlMax (this->HScroll, newMax = AreaWidth());
- SetCtlValue (this->HScroll, newMax * oldValue / oldMax);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::SetVerticalStep (short stepSize)
- /* change the step size of the vertical scroll bar; adjust */
- /* the current value of the scrollbar as necessary */
- {
- short oldValue, oldMax, newMax;
-
- if (this->vStep != stepSize)
- {
- this->vStep = stepSize;
- if (this->VScroll)
- {
- oldValue = GetCtlValue(this->VScroll);
- oldMax = GetCtlMax(this->VScroll);
-
- SetCtlMax (this->VScroll, newMax = AreaHeight());
- SetCtlValue (this->VScroll, newMax * oldValue / oldMax);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::MoveScrollArea (void)
- {
- long ScrollValue,
- height, i, j,
- HScrollDiff = 0, VScrollDiff = 0,
- OldScroll, NewScroll;
- RgnHandle updateRgn = NewRgn(),
- oldClipRgn = NewRgn();
- Rect tempRect = this->areaRect;
-
- InsetRect (&tempRect, 1, 1);
-
- if (this->VScroll)
- {
- tempRect.right++;
- OldScroll = this->viewRect.top - this->destRect.top;
- ScrollValue = GetCtlValue (this->VScroll);
- NewScroll = ScrollValue * this->vStep;
- VScrollDiff = OldScroll - NewScroll;
- }
-
- if (this->HScroll)
- {
- tempRect.bottom++;
- OldScroll = this->viewRect.left - this->destRect.left;
- ScrollValue = GetCtlValue (this->HScroll);
- NewScroll = ScrollValue * this->hStep;
- HScrollDiff = OldScroll - NewScroll;
- }
-
- // do the scrolling, if any is required
- if (VScrollDiff + HScrollDiff != 0)
- ScrollRect(&tempRect, HScrollDiff, VScrollDiff, updateRgn);
- OffsetRect (&this->viewRect, -HScrollDiff, -VScrollDiff);
- OffsetRgn (updateRgn, viewRect.left - areaRect.left,
- viewRect.top - areaRect.top);
-
-
- GetClip (oldClipRgn);
- SectRgn (updateRgn, oldClipRgn, updateRgn);
- SetClip (updateRgn);
-
- this->Draw();
-
- SetClip (oldClipRgn);
- DisposeRgn(updateRgn);
- DisposeRgn(oldClipRgn);
- }
-
- /*-----------------------------------------------------------------*/
- /*---------------------- PROTECTED METHODS ------------------------*/
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::ResizeContent (short newWidth, short newHeight)
- {
- Rect VCRect, HCRect, GrowRect, ViewRect, DestRect;
- Rect PRect;
-
- if (this->owningWindow)
- {
- // resize the actual on-screen area;
- this->areaRect.right = this->areaRect.left + 1 +
- newWidth - ((this->VScroll) ? 15 : 0);
- this->areaRect.bottom = this->areaRect.top + 1 +
- newHeight - ((this->HScroll) ? 15 : 0);
-
- // set the new size of the view area
- this->viewRect.right = this->viewRect.left +
- (this->areaRect.right - this->areaRect.left);
- this->viewRect.bottom = this->viewRect.top +
- (this->areaRect.bottom - this->areaRect.top);
-
- // move and resize the controls
- if (this->HScroll)
- {
- HideControl (this->HScroll);
- MoveControl (this->HScroll, this->areaRect.left, this->areaRect.bottom);
- SizeControl (this->HScroll, (this->areaRect.right - this->areaRect.left) + 1, 16);
- ShowControl (this->HScroll);
- }
-
- if (this->VScroll)
- {
- HideControl (this->VScroll);
- MoveControl (this->VScroll, this->areaRect.right, this->areaRect.top);
- SizeControl (this->VScroll, 16, (this->areaRect.bottom - this->areaRect.top) + 1);
- ShowControl (this->VScroll);
- }
-
- // adjust the positions of everything
- if (viewRect.right > destRect.right)
- OffsetRect (&this->viewRect, destRect.right - viewRect.right, 0);
- if (viewRect.bottom > destRect.bottom)
- OffsetRect (&this->viewRect, 0, destRect.bottom - viewRect.bottom);
- AdjustScrollBar();
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::MoveContent (short newH, short newV)
- {
- Rect vRect, dRect, bRect = *GetBounds();
- short deltaH = newH - bRect.left,
- deltaV = newV - bRect.top;
-
- // move the visible area
- OffsetRect (&this->areaRect, deltaH, deltaV);
-
- // move the vertical scroll bar
- if (this->VScroll)
- {
- vRect = (*this->VScroll)->contrlRect;
- MoveControl (this->VScroll, vRect.left + deltaH,
- vRect.top + deltaV);
- }
-
- // move the horizontal scroll bar
- if (this->HScroll)
- {
- dRect = (*this->HScroll)->contrlRect;
- MoveControl (this->HScroll, dRect.left + deltaH,
- dRect.top + deltaV);
- }
- }
-
- /*-----------------------------------------------------------------*/
- /*----------------------- PRIVATE METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- pascal void CPPScrollArea::Scroll_Up (ControlHandle theControl, short ctlPart)
- /* this method serves as a callback routine for TrackControl; */
- /* It forces the area to scroll up 1 line */
- {
- if (theControl && (GetCtlValue(theControl) - 1 >= GetCtlMin(theControl)))
- {
- SetCtlValue (theControl, GetCtlValue (theControl)-1);
- gCurrentArea->MoveScrollArea();
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- pascal void CPPScrollArea::Scroll_Down (ControlHandle theControl,
- short ctlPart)
- /* this method serves as a callback routine for TrackControl; */
- /* It forces the area to scroll down 1 line */
- {
- if (theControl && (GetCtlValue(theControl) + 1 <= GetCtlMax(theControl)))
- {
- SetCtlValue (theControl, GetCtlValue (theControl)+1);
- gCurrentArea->MoveScrollArea();
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- pascal void CPPScrollArea::Scroll_Left (ControlHandle theControl,
- short ctlPart)
- /* this method serves as a callback routine for TrackControl; */
- /* It forces the area to scroll left 1 line */
- {
- if (theControl && (GetCtlValue(theControl) - 1 >= GetCtlMin(theControl)))
- {
- SetCtlValue (theControl, GetCtlValue (theControl)-1);
- gCurrentArea->MoveScrollArea();
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- pascal void CPPScrollArea::Scroll_Right (ControlHandle theControl,
- short ctlPart)
- /* this method serves as a callback routine for TrackControl; */
- /* It forces the area to scroll right 1 line */
- {
- if (theControl && (GetCtlValue(theControl) + 1 <= GetCtlMax(theControl)))
- {
- SetCtlValue (theControl, GetCtlValue (theControl)+1);
- gCurrentArea->MoveScrollArea();
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Area2Local (Point *thePoint)
- /* convert from scroll area coordinates to window coordinates */
- {
- thePoint->h -= this->areaRect.left;
- thePoint->v -= this->areaRect.top;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Local2Area (Point *thePoint)
- /* convert from window coordinates to scroll area coordinates */
- {
- thePoint->h += this->areaRect.left;
- thePoint->v += this->areaRect.top;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Area2Global (Point *thePoint)
- /* convert from scroll area coordinates to global coordinates */
- {
- WindowPtr theWindow = this->owningWindow;
-
- if (theWindow)
- {
- // first convert it from area to local
- Area2Local (thePoint);
- // then convert from local to global
- thePoint->h -= theWindow->portRect.left;
- thePoint->v -= theWindow->portRect.top;
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::Global2Area (Point *thePoint)
- /* convert from global coordinates to scroll area coordinates */
- {
- WindowPtr theWindow = this->owningWindow;
-
- if (theWindow)
- {
- // first convert from global to local
- thePoint->h += theWindow->portRect.left;
- thePoint->v += theWindow->portRect.top;
- // then convert from local to area
- Local2Area (thePoint);
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::AutoScroll (void)
- /* This routine will cause the area to scroll to follow the */
- /* mouse */
- {
- Point mouseLoc;
-
- GetMouse (&mouseLoc);
-
- if (mouseLoc.v < this->areaRect.top)
- Scroll_Up (gVScroll, inUpButton);
- else
- if (mouseLoc.v > this->areaRect.bottom)
- Scroll_Down (gVScroll, inDownButton);
-
- if (mouseLoc.h > this->areaRect.right)
- Scroll_Right (gHScroll, inDownButton);
- else
- if (mouseLoc.h < this->areaRect.left)
- Scroll_Left (gHScroll, inUpButton);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::VPageScroll (long part, long direction)
- /* Scroll the text 1 page either up or down */
- {
- Point tempPt;
- short newValue, page;
-
- if (this->VScroll)
- {
- GetMouse (&tempPt);
- while (StillDown())
- {
- if (TestControl(this->VScroll, tempPt) == part)
- {
- page = direction * (ViewHeight() - 1);
- newValue = GetCtlValue (this->VScroll) + page;
- SetCtlValue (this->VScroll, newValue);
- MoveScrollArea();
- }
- GetMouse (&tempPt);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::HPageScroll (long part, long direction)
- /* Scroll the text 1 page either left or right */
- {
- Point tempPt;
- short newValue, page;
-
- if (this->HScroll)
- {
- GetMouse (&tempPt);
- while (StillDown())
- {
- if (TestControl(this->HScroll, tempPt) == part)
- {
- page = direction * (ViewWidth()-1);
- newValue = GetCtlValue (this->HScroll) + page;
- SetCtlValue (this->HScroll, newValue);
- MoveScrollArea();
- }
- GetMouse (&tempPt);
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPScrollArea::AreaWidth (void)
- /* return the number of horizontal lines in the entire scroll area */
- {
- return ((this->destRect.right - this->destRect.left) / this->hStep);
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPScrollArea::AreaHeight (void)
- /* return the number of vertical lines in the entire scroll area */
- {
- return ((this->destRect.bottom - this->destRect.top) / this->vStep);
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPScrollArea::ViewWidth (void)
- /* return the number of horizontal lines in the visible scroll area */
- {
- return ((this->viewRect.right - this->viewRect.left) / this->hStep);
- }
-
- /*-----------------------------------------------------------------*/
-
- long CPPScrollArea::ViewHeight (void)
- /* return the number of vertical lines in the visible scroll area */
- {
- return ((this->viewRect.bottom - this->viewRect.top) / this->vStep);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::AdjustScrollBar (void)
- /* This procedure turns the scroll bars off if there are fewer */
- /* lines than space for lines, and turns them on if there are more */
- {
- if (this->HScroll)
- SetCtlMax (this->HScroll, Max(0, AreaWidth() - ViewWidth()));
- if (this->VScroll)
- SetCtlMax (this->VScroll, Max(0, AreaHeight() - ViewHeight()));
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoVScroller (Point clickPt, short part)
- /* Handle a click in the vertical scroll bar */
- {
- long Result;
-
- gCurrentArea = this;
-
- if (this->VScroll)
- {
- switch (part) {
- case inUpButton :
- Result = TrackControl(this->VScroll, clickPt,
- (ProcPtr)Scroll_Up);
- break;
- case inDownButton :
- Result = TrackControl(this->VScroll, clickPt,
- (ProcPtr)Scroll_Down);
- break;
- case inPageUp :
- VPageScroll (part, -1);
- break;
- case inPageDown :
- VPageScroll (part, 1);
- break;
- case inThumb :
- TrackControl (this->VScroll, clickPt, NULL);
- MoveScrollArea();
- break;
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::DoHScroller (Point clickPt, short part)
- /* Handle a click in the horizontal scroll bar */
- {
- long Result;
-
- gCurrentArea = this;
-
- if (this->HScroll)
- {
- switch (part) {
- case inUpButton :
- Result = TrackControl(this->HScroll, clickPt,
- (ProcPtr)Scroll_Left);
- break;
- case inDownButton :
- Result = TrackControl(this->HScroll, clickPt,
- (ProcPtr)Scroll_Right);
- break;
- case inPageUp :
- HPageScroll (part, -1);
- break;
- case inPageDown :
- HPageScroll (part, 1);
- break;
- case inThumb :
- TrackControl (this->HScroll, clickPt, NULL);
- MoveScrollArea();
- break;
- }
- }
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPScrollArea::MakeCPPScrollArea (CPPWindow *OurWindow,
- Rect *ViewArea,
- Rect *DestArea,
- Boolean UseHScroll,
- Boolean UseVScroll,
- short hStep,
- short vStep)
- {
- Rect tempRect;
-
- // set the control step size
- this->hStep = hStep;
- this->vStep = vStep;
-
- /* figure out where the area and view rectangles are */
- this->destRect = *DestArea;
- this->areaRect = *ViewArea;
- this->areaRect.right -= (UseVScroll) ? 15 : 0;
- this->areaRect.bottom -= (UseHScroll) ? 15 : 0;
- SetRect (&this->viewRect, 0, 0,
- areaRect.right - areaRect.left,
- areaRect.bottom - areaRect.top);
- this->selRect = kEmptyRect;
- this->hasSelection = FALSE;
-
- // create the vertical scroll bar
- if (UseVScroll)
- {
- SetRect (&tempRect, areaRect.right, areaRect.top-1,
- areaRect.right + 16, areaRect.bottom+1);
- this->VScroll = NewControl (OurWindow->GetWindow(),
- &tempRect, "\pVScroll",
- TRUE, 0, 0,
- AreaHeight() - ViewHeight(),
- scrollBarProc, 13);
- }
- else this->VScroll = NULL;
-
- // create the horizontal scroll bar
- if (UseHScroll)
- {
- SetRect (&tempRect, areaRect.left-1, areaRect.bottom,
- areaRect.right+1, areaRect.bottom + 16);
- this->HScroll = NewControl (OurWindow->GetWindow(),
- &tempRect, "\pHScroll",
- TRUE, 0, 0,
- AreaWidth() - ViewWidth(),
- scrollBarProc, 13);
- }
- else this->HScroll = NULL;
-
- }
-
-
-
-
-
-